import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

public class Test3 {
    public static void main(String[] args) {
        // 掌握Stream流中常见的中间方法
        ArrayList<Object> Score = new ArrayList<>();
        Collections.addAll(Score, 98.3, 95.0, 18.9, 45.0, 50.9);
        // 找出成绩大于等于60分的数据 并升序排序后  输出
        Score.stream().filter(s -> (double)s >= 60).sorted().forEach(System.out::println);

        List<Student> Students = new ArrayList<>();
        Student s1 = new Student("蜘蛛精", 26, 172.5);
        Student s2 = new Student("蜘蛛精",26, 172.5);
        Student s3 = new Student("紫霞",23, 167.6);
        Student s4 = new Student("白晶晶",25, 169.0);
        Student s5 = new Student("牛魔王",35, 183.3);
        Student s6 = new Student("牛夫人",34, 168.5);
        Collections.addAll(Students, s1, s2, s3, s4, s5, s6);

        // 需求2 找出年龄大于等于23,且年龄小于等于30岁的学生，并按照年龄降序输出
        Students.stream().filter(s -> s.getAge() >= 23 && s.getAge() <=30).sorted(
                ((o1, o2) -> o2.getAge() - o1.getAge())
        ).forEach(System.out::println);
        // 需求3:取出身高最高的前3名学生，并输出
        Students.stream().sorted((o1,o2) ->Double.compare(o2.getHeight(), o1.getHeight())).limit(3).forEach(System.out::println);

        // 需求4:取出身高倒数的2名学生，并输出
        Students.stream().sorted((o1,o2) ->Double.compare(o2.getHeight(), o1.getHeight())).skip(Students.size() - 2).forEach(System.out::println);
        // 需求5:找出身高超过168的学生叫什么名字，要求去除重复的名字，再输出
        Students.stream().filter(s -> s.getHeight() > 168).map(Student::getName).distinct().forEach(System.out::println);

        // 将两个流合并  concat
        Stream<String> st1 = Stream.of("张三", "李四");
        Stream<String> st2 = Stream.of("张三1", "李四2","王五");
        Stream.concat(st1, st2).forEach(System.out::println);



    }
}
